<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>News</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<link type="text/css" rel="stylesheet" href="css/map.css" />
	<link type="text/css" rel="stylesheet" href="../../css/pepper-grinder/jquery-ui-1.8.16.custom.css" />
	<script type="text/javascript" src="../../js/jquery.min.js"></script>
	<script type="text/javascript" src="../../js/jquery-ui-1.8.16.custom.min.js"></script>
	<script src="http://api.map.baidu.com/api?v=1.2" type="text/javascript"></script>
	<script language="JavaScript" type="text/JavaScript">
		$(document).ready(function() {
			$(window).resize(function() {
				refresh();
			});	
			map = new BMap.Map("container");          // 创建地图实例
			var point = new BMap.Point(116.404, 39.915);  // 创建点坐标
			map.centerAndZoom(point, 15);                 // 初始化地图，设置中心点坐标和地图级别
			map.enableScrollWheelZoom();                  // 启用滚轮放大缩小。
			map.enableKeyboard();                         // 启用键盘操作。
			var opts = {type: BMAP_NAVIGATION_CONTROL_SMALL}  
			map.addControl(new BMap.NavigationControl(opts)); 
			
			var myCity = new BMap.LocalCity();
			myCity.get(myFun);

		});
		function refresh(){
			var winheight = $(window).height();
			var winwidth = $(window).width();
			
			$("#bodydiv").css("height",winheight);
			$("#box").css("height",winheight-40);
			$("#container").css("height",winheight-40);
			
		}
		function showNews(obj){
			window.parent.showapp("compents/map/shownews.html?id="+obj.id);
		}
		function myFun(result){
				cityname = result.name;
				map.setCurrentCity(cityname);  
				//map.setCenter(cityname);
				goMap(cityname);
				
		}

		function goMap(address){
			// 创建地址解析器实例
			var myGeo = new BMap.Geocoder();
			
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(address, function(point){
				
				if (point) {
					map.centerAndZoom(point, 16);
					var marker = new BMap.Marker(point);
					map.addOverlay(marker);
					//添加热区
					//var hotSpot = new BMap.Hotspot(point, {text: address, minZoom: 8, maxZoom: 18});
					//map.addHotspot(hotSpot);
					
					var sContent = "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>"+address+"</h4>";
						
					
					var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
					
					marker.addEventListener("click", function(){  
						
						this.openInfoWindow(infoWindow);  
					});
					
				}else{
					
					goDefaultMap();

				}
			}, cityname);
			

			
		}

		function goDefaultMap(){
			// 创建地址解析器实例
			var myGeo = new BMap.Geocoder();
			
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(cityname, function(point){
				
				if (point) {
					map.centerAndZoom(point, 16);
					var marker = new BMap.Marker(point);
					map.addOverlay(marker);
					//添加热区
					//var hotSpot = new BMap.Hotspot(point, {text: address, minZoom: 8, maxZoom: 18});
					//map.addHotspot(hotSpot);
					var sContent =
						"<h4 style='margin:0 0 5px 0;padding:0.2em 0'>"+cityname+"</h4>" + 
						"<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>请输入详细地址</p>" +
						"<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'><input type='text' id='newadress'><input type='button' value='更新' onclick='modifyMap();'/></p>";
					
					var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
					
					marker.addEventListener("click", function(){  
						
						this.openInfoWindow(infoWindow);  
					});
				}else{
					
					map.setCenter(cityname);

				}
			}, cityname);
		}
		function modifyMap(){
			var newadress = $("#searchInput").val();
			goMap(newadress);

		}
		function localSearch(title){
			var local = new BMap.LocalSearch(map, {  
				renderOptions:{map: map, autoViewport: true}  
			});  
			local.searchInBounds(title, map.getBounds());  
			//local.searchNearby("学校", address);
		}
		
	</script>
</head>
<body style="background-color=transparent;width:100%;margin-left:0px;margin-top:0px;">
	<div id="bodydiv" style="background:url(../../image/bg/4.png)">
		<div style="width:100%;height:40px;padding-left:25px;float:left;">
			<div style="float:left;padding-top:15px;">地点搜索：</div>
			<div style="float:left;padding-top:9px;"><input type="text" id="searchInput" ></div>
			<div style="float:left;"><img onclick="modifyMap();" title="搜索" src="../../image/icon/png-0005.png" style="width:22px;height:22px;cursor:pointer;padding-top:10px;" /> </div>
			<div style="float:left;padding-top:15px;padding-left:20px;">周边搜索：</div>
			<div style="float:left;padding-left:5px;"><img onclick="localSearch('银行');" title="银行" src="images/1.png" style="width:16px;height:16px;cursor:pointer;padding-top:15px;" /> </div>
			<div style="float:left;padding-left:5px;"><img onclick="localSearch('餐饮');" title="餐饮" src="images/2.png" style="width:16px;height:16px;cursor:pointer;padding-top:15px;" /> </div>
			<div style="float:left;padding-left:5px;"><img onclick="localSearch('商场');" title="商场" src="images/3.png" style="width:16px;height:16px;cursor:pointer;padding-top:15px;" /> </div>
			<div style="float:left;padding-left:5px;"><img onclick="localSearch('医院');" title="医院" src="images/4.png" style="width:16px;height:16px;cursor:pointer;padding-top:15px;" /> </div>
			<div style="float:left;padding-left:5px;"><img onclick="localSearch('公交');" title="公交" src="images/5.png" style="width:16px;height:16px;cursor:pointer;padding-top:15px;" /> </div>
			
		</div>
		<div id="box" style="float:left;width:100%;" >
			<div id="container" ></div>
		</div>

	</div>
</body>
</html>